import 'package:flutter/material.dart';

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    List<int> list = [];
    for (var i = 1; i < 21; i++) {
      list.add(i);
    }
    // final size = MediaQuery.of(context).size;
    // NumberFormat formatter = NumberFormat("0000");
    return Wrap(
      // direction: Axis.vertical,
      spacing: 10,
      runSpacing: 10,
      alignment: WrapAlignment.spaceEvenly,
      children: list
          .map((e) => Button(
                "第 $e 集",
                onPressed: () {},
              ))
          .toList(),
    );
  }
}

/// 自定义按钮组件
class Button extends StatelessWidget {
  String text;
  void Function()? onPressed = () => {};

  Button(this.text, {super.key, this.onPressed});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
        style: ButtonStyle(
          backgroundColor: MaterialStateProperty.all(Colors.black12),
          foregroundColor: MaterialStateProperty.all(Colors.black54),
          padding: MaterialStateProperty.all(const EdgeInsets.all(1)),
        ),
        onPressed: onPressed,
        child: Text(text));
  }
}
